<?php 
define('IN_WONDERSHARE', true);
header("Content-type:text/html;charset=utf-8");
ob_start("ob_gzhandler");
require('../includes/init.php');
require('./classes/control/control_feature.php');

class Feature
{
	var $feature_c;
	function __construct(){
	
		$this->feature_c = new FeatureControl();
	}
	//标签管理
	function index()
	{
	
		if($_REQUEST['act'] == 'list')//特点16个列表
		{
			$insert = '';
			if($_POST['sub_from'])
			{
				$product_id = (int)$_POST['product_id'];
				if(!empty($product_id))
				{
					for($i=1;$i<=8;$i++)
					{
						if(empty($_POST['feature_id_'.$i]))
						{
							$insert.= "('".$product_id."','".$_POST['feature_title'.$i]."','".$_POST['feature_pic_min'.$i]."','".$_POST['feature_pic_max'.$i]."',
							'".$_POST['feature_intro'.$i]."','0','$i','".$_SERVER['REQUEST_TIME']."','".$_SESSION['AName']."'),";
						}else
						{
							$update ="UPDATE feature   SET  feature_title = '".$_POST['feature_title'.$i]."' ,feature_intro = '".$_POST['feature_intro'.$i]."',
							feature_pic_min = '".$_POST['feature_pic_min'.$i]."' , update_time = '".$_SERVER['REQUEST_TIME']."',update_user = '".$_SESSION['AName']."',
							feature_pic_max = '".$_POST['feature_pic_max'.$i]."' WHERE  feature_id = '".$_POST['feature_id_'.$i]."'  ";
							$change_rows = $this->feature_c->insert_feature_info($update,$product_id,'update');//修改
						}
						if(empty($_POST['more_feature_id_'.$i]))
						{
						
							$insert.= "('".$product_id."','".$_POST['more_feature_title'.$i]."','".$_POST['more_feature_pic_min'.$i]."',
							'".$_POST['more_feature_pic_max'.$i]."','".$_POST['more_feature_intro'.$i]."',1,'$i','".$_SERVER['REQUEST_TIME']."','".$_SESSION['AName']."'),";
						}else
						{
							$update ="UPDATE feature   SET  feature_title = '".$_POST['more_feature_title'.$i]."' ,feature_intro = '".$_POST['more_feature_intro'.$i]."',
							feature_pic_min = '".$_POST['more_feature_pic_min'.$i]."' , update_time = '".$_SERVER['REQUEST_TIME']."',update_user = '".$_SESSION['AName']."',
							feature_pic_max = '".$_POST['more_feature_pic_max'.$i]."' WHERE  feature_id = '".$_POST['more_feature_id_'.$i]."'   ";
							$change_rows = $this->feature_c->insert_feature_info($update,$product_id,'update');//修改
						}
					
					}
				
					if(!empty($insert))
					{
					
						$insert = substr($insert, 0, strlen($insert) - 1) ;
						$change_rows = $this->feature_c->insert_feature_info($insert,$product_id,'add');//批量插入
					}
					$insert = $update = '';
					if($change_rows>0)
					{
						echo  '<script type="text/javascript"> alert("修改成功！");
						window.location.href="/wondershare/feature.php?action=index"; </script>';
					}
				}
			}
		
			$more_feature = $more_feature = array();
			$feature = $this->feature_c->get_feature_info('p_feature',0,0,0,(int)$_GET['p_id'],0);//得到feature
			$more_feature = $this->feature_c->get_feature_info('p_feature',0,0,0,(int)$_GET['p_id'],1);//得到more_feature
			$sum_array = array(1=>1,3=>3,5=>5,7=>7);
			$GLOBALS['smarty']->assign('product_id',   (int)$_GET['p_id']);
			$GLOBALS['smarty']->assign('feature',   $feature);
			$GLOBALS['smarty']->assign('more_feature',   $more_feature);
			$GLOBALS['smarty']->assign('sum_array',   $sum_array);
			$GLOBALS['smarty']->display('feature_list.htm'); 
		}elseif($_GET['in_jax'] == 1)
		{
			$type = $_GET['type'];
			$value = $_GET['value'];
			switch($type) 
			{
				case 'title':
					$field = 'feature_title';
					break;
				case 'pic_min':
					$field = 'feature_pic_min';
					break;
				case 'pic_max':
					$field = 'feature_pic_max';
					break;
			}
			if (!empty($_GET['feature_id']))
			$this->feature_c->change_info((int)$_GET['feature_id'],$value,$field);
		}elseif($_REQUEST['act'] == 'edit')//修改
		{
			$feature_info = array();
			if($_POST['sub_from'])
			{
				if(!empty($_POST['f_id']))
				{
					//删除队列
					queueDelete(0, $_POST['f_id']);
						
					$affect = $this->feature_c->update_feature((int)$_POST['f_id'],$_POST['title'],$_POST['pic_min']
					,$_POST['pic_max'],$_POST['intro']);
					if($affect == 1)
					{
					echo  '<script type="text/javascript"> alert("修改成功！");
					window.location.href="/wondershare/feature.php?action=index"; </script>';
					}
				}
			} else {
				//加入队列
				queueInfo($_GET['feature_id']);
			}
			$feature_info = $this->feature_c->get_feature_info('a_record',0,0,(int)$_GET['feature_id']);
			
			$GLOBALS['smarty']->assign('tile',     '修改');
			$GLOBALS['smarty']->assign('form_act',     'edit');
			$GLOBALS['smarty']->assign('feature_info',$feature_info[0] );
			$GLOBALS['smarty']->display('feature_info.htm'); 
		}else
		{
			$url_info = $feature_info = array();
			//分页处理
			$page = 1;
			if (!empty($_REQUEST['page'])) {
				$page = (int)$_REQUEST['page'];
			}
			if($_POST['search']||$_REQUEST['url_page'] == 1)
			{
			
			$_SESSION['fage'] = $_REQUEST['url_page'] == 1 ?1:0;
			$feature_title = $_REQUEST['url_page'] == 1 ? urldecode($_REQUEST['feature_title']):$_REQUEST['feature_title'];
			$url_info = $this->feature_c->get_url_info($page,16,'list_s',$_REQUEST['feature_type'],$_REQUEST['product_id'],
			$feature_title);
			$feature_info = $this->feature_c->get_feature_info('list_s',$url_info['page_info']['start'],16,0
			,$_REQUEST['product_id'],$_REQUEST['feature_type'],$feature_title);
			}else
			{
				$url_info = $this->feature_c->get_url_info($page,16,'list');
				$feature_info = $this->feature_c->get_feature_info('list',$url_info['page_info']['start'],16);
			
			}
			$GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
			$GLOBALS['smarty']->assign('feature_info',$feature_info );
			$GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
			
			$GLOBALS['smarty']->display('feature_index.htm'); 
		}	
	}


}

$action    = $_REQUEST['action']; 
$feature   = new Feature;
if(method_exists($feature, $action)) 
{
	$feature->$action();
}else{
	$feature->index();
}

?>
